﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 
// See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Actors.Utilities;
using System.Threading.Tasks;

namespace System.Threading.Actors
{
    // WinFab implementation of IActorProxy
    // Basically provides an IActorProxy wrapper around a FabricActorClient.
    // NOTE: Needed to make this public so that StatelessActorService could have access to it.  Kinda makes me wince, but there is no simple way around it.
    public class FabricActorProxy : ActorProxyBase
    {
        public FabricActorProxy(string actorName, IActorState sourceState, string targetPartitionName = null, string myPartitionName = null)
            : base(new FabricActorClient(null, new Uri(actorName), false, targetPartitionName), sourceState, targetPartitionName, myPartitionName)
        {
            Contract.Requires(actorName != null);
        }

        private FabricActorProxy(FabricActorClient fac, IActorState sourceState, string targetPartitionName, string myPartitionName)
            : base(fac, sourceState, targetPartitionName, myPartitionName)
        {

        }

        public static async Task<FabricActorProxy> CreateAsync(string actorName, IActorState sourceState, string targetPartitionName = null, string myPartitionName = null)
        {
            FabricActorClient fac = await FabricActorClient.CreateAsync(null, new Uri(actorName), false, targetPartitionName);
            return new FabricActorProxy(fac, sourceState, targetPartitionName, myPartitionName);
        }


    }

}
